package dilmaj.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dilmaj.client.StarEntryJDO;
import dilmaj.server.*;
import dilmaj.shared.StarEntryVO;
import dilmaj.shared.TermVO;

public class DilmajData extends HttpServlet {
	  @Override
	  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	      throws ServletException, IOException {

		  resp.setContentType("text/plain; charset=UTF-8");
			resp.setHeader("content", "locale=ar_SA");
	    //Random rnd = new Random();
		List<StarEntryVO> allTerms=dilmaj.server.StarServiceImpl.staticLoadAll();

		PrintWriter out = resp.getWriter();
	    out.println('[');
	    //String[] stockSymbols = req.getParameter("q").split(" ");
	    //for (String stockSymbol : stockSymbols) {
	    Iterator iterator=allTerms.iterator();
	    while (iterator.hasNext()) {
	    	StarEntryVO termJDO=(StarEntryVO)iterator.next();
	      out.println("  {");
	      out.print("    \"caption\": \"");
	      out.print(termJDO.getCaption());
	      out.println("\",");
	      out.print("    \"id\": ");
	      out.print(termJDO.getId());
	      out.println(',');
	      out.print("    \"rank\": ");
	      out.print(termJDO.getRank());
	      out.println(',');
	      out.print("    \"description\": ");
	      out.print(termJDO.getDescription());
	      out.println(',');
	      out.print("    \"title\": ");
	      out.print(termJDO.getTitle());
	      out.println(',');
	      out.print("    \"userid\": ");
	      out.print(termJDO.getUserID());
	      out.println(',');
	      out.print("    \"username\": ");
	      out.print(termJDO.getUsername());
	      out.println(',');
	      out.print("    \"atttachmentsID\": ");
	      out.print(termJDO.getAttachmentString());
	      out.println("  },");
	    }
	    out.println(']');
	    out.flush();
	  }
}
